package com.taowan.xunbaozl.morning_speak.uiview.day01;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.ArrowKeyMovementMethod;
import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.util.TypedValue;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.taowan.xunbaozl.morning_speak.R;

import junit.framework.Test;

/**
 * Created by 杨观回 on 2016/3/27 0027.
 */
public class TestActivity extends Activity {

    private TextView tv_test1;
    private TextView tv_test2;
    private TextView tv_test3;
    private EditText et_test4;
    private TextView tv_test5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        tv_test1 = (TextView) findViewById(R.id.tv_test1);
        tv_test2 = (TextView) findViewById(R.id.tv_test2);
        tv_test3 = (TextView) findViewById(R.id.tv_test3);
        et_test4 = (EditText) findViewById(R.id.et_test4);
        tv_test5 = (TextView) findViewById(R.id.tv_test5);
        test1();
        test2();
        test3();
        test4();
        test5();
    }


    /**
     * 可设置html代码
     */
    private void test1() {
        String html = "<font color='red'>测试</font><br>";
        html += "<font color='green'><big><i>I love android</i></big></font><br><p>";
        CharSequence charSequence = Html.fromHtml(html);
        tv_test1.setText(charSequence);
    }

    /**
     * setSize 默认为sp
     */
    private void test2() {
        tv_test2.setText("测试22222222");
        tv_test2.setTextSize(20);//sp
        tv_test2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);//dp
    }

    /**
     * BackgroundColorSpan：背景颜色
     * ClickableSpan    设置可点击的部分文字
     * ForegroundColorSpan  改变文字字体的颜色
     * MaskFilterSpan(MaskFilter filter) 修饰效果，如模糊（BlurMaskFilter）、浮雕（EmbossMaskFilter）
     * MetricAffectingSpan
     * 直接子类：  AbsoluteSizeSpan, LocaleSpan, RelativeSizeSpan, ReplacementSpan, ScaleXSpan, StyleSpan, SubscriptSpan, SuperscriptSpan, TextAppearanceSpan, TypefaceSpan
     * 间接子类：  DynamicDrawableSpan， ImageSpan
     * RasterizerSpan 光栅效果
     * StrikethroughSpan  中划线 （删除线）
     * SuggestionSpan 占位符
     * UnderlineSpan 下划线
     * ImageSpan 图片包裹，可以在一段文字中添加一个图片
     * SubscriptSpan 下标- 数学公式 用到
     * SuperscriptSpan 上标-数学公式会用到
     * ScaleXSpan(3.8f) 基于x轴的缩放
     * StyleSpan(Typeface.BOLD_ITALIC)字体样式：粗体、斜体等
     * TextAppearanceSpan(this, android.R.style.TextAppearance_Medium) 文本外貌（包括字体、大小、样式和颜色）
     * TypefaceSpan("monospace")文本字体
     * URLSpan("http://orgcent.com") 文本超链接
     */
    private void test3() {
        SpannableString sp = new SpannableString("这句话中有百度超链接,有高亮显示，这样，或者这样，还有斜体.");
        //设置超链接
        sp.setSpan(new URLSpan("http://www.baidu.com"), 5, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        //设置高亮样式一
        sp.setSpan(new BackgroundColorSpan(Color.RED), 17, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置高亮样式二
        sp.setSpan(new ForegroundColorSpan(Color.YELLOW), 20, 24, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //设置斜体
        sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 27, 29, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        sp.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Toast.makeText(TestActivity.this, "点击点击", Toast.LENGTH_LONG).show();
            }
        }, 8, 12, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //用删除线标记文本
        sp.setSpan(new StrikethroughSpan(), 7, 10,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //用下划线标记文本
        sp.setSpan(new UnderlineSpan(), 10, 16,
                Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        //SpannableString对象设置给TextView
        tv_test3.setText(sp);
        //设置TextView可点击
        tv_test3.setMovementMethod(LinkMovementMethod.getInstance());
    }

    /**
     * Spanned.SPAN_EXCLUSIVE_EXCLUSIVE(前后不包含)
     * Spanned.SPAN_EXCLUSIVE_INCLUSIVE(前不包含，后包含)
     * Spanned.SPAN_INCLUSIVE_EXCLUSIVE。。
     * Spanned.SPAN_INCLUSIVE_INCLUSIVE
     */
    public void test4() {
        SpannableString sp = new SpannableString("这句话中有百度超链接,有高亮显示，这样，或者这样，还有斜体.");
        //设置超链接
        sp.setSpan(new URLSpan("http://www.baidu.com"), 5, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        //设置高亮样式一
        sp.setSpan(new BackgroundColorSpan(Color.RED), 17, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置高亮样式二
        sp.setSpan(new ForegroundColorSpan(Color.YELLOW), 20, 24, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //设置斜体
        sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 27, 29, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        sp.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Toast.makeText(TestActivity.this, "点击点击", Toast.LENGTH_LONG).show();
            }
        }, 8, 12, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //用删除线标记文本
        sp.setSpan(new StrikethroughSpan(), 7, 10,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //用下划线标记文本
        sp.setSpan(new UnderlineSpan(), 10, 16,
                Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        //SpannableString对象设置给TextView
        et_test4.setText(sp);
    }


    /**
     * ScrollingMovementMethod 使textview可滚动
     * LinkMovementMethod  可点击
     * ArrowKeyMovementMethod ...光标移动的作用
     */
    public void test5() {
        tv_test5.setMovementMethod(ScrollingMovementMethod.getInstance());
    }


    /**
     * 字数过多，滚动 动画效果
     *  android:ellipsize="marquee"
     android:marqueeRepeatLimit="marquee_forever"
     */
    public void test6(){}

}
